package com.example.demo.export.main;

import com.example.demo.export.entity.Person;
import com.example.demo.export.exportInterface.ExportInterface;
import com.example.demo.export.exportInterfaceTask.ExportInterfaceTask;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类描述:
 *
 * @author jianweiwang
 * @version v1.0
 * @link wjw@choicesoft.com.cn
 * @date 2018/12/11 16:25
 **/
public class Main {


    public static void main(String[] args) {
        List<Person> list = Person.getData();
        List<Map<String,Object>> clist = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        map.put("column","id");
        map.put("columnName","ID");
        clist.add(map);
        map = new HashMap<>();
        map.put("column","name");
        map.put("columnName","名称");
        clist.add(map);
        map = new HashMap<>();
        map.put("column","age");
        map.put("columnName","年龄");
        clist.add(map);
        map = new HashMap<>();
        map.put("column","gender");
        map.put("columnName","性别");
        clist.add(map);
        Book book = new Book();
        HSSFWorkbook workbook = book.getBook(list,clist);

        FileOutputStream fileOutputStream;
        try {
            String filePath = "E:\\myself\\ceshi.xls";
            fileOutputStream = new FileOutputStream(filePath);
            workbook.write(fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
class Book{
    ExportInterface exportInterface = new ExportInterfaceTask();
    protected HSSFWorkbook getBook(List<Person> data, List<Map<String,Object>> columnsData) {
        return exportInterface.createBook(data, columnsData);
    }
}